package logic

import (
	"VipSrv/global/model"
	"VipSrv/global/pkg"
	"VipSrv/internal/svc"
	"VipSrv/vip"
	"context"
	"github.com/google/uuid"

	"github.com/zeromicro/go-zero/core/logx"
)

type VipAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVipAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VipAddLogic {
	return &VipAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VipAddLogic) VipAdd(in *vip.VipAddRequest) (*vip.VipAddResponse, error) {
	// todo: add your logic here and delete this line
	var Vip = model.Vip{
		Price:     0,
		Month:     0,
		Snow:      uuid.NewString()[:16],
		VipStatus: "wait pay",
		UserId:    int(in.UserId),
	}
	switch in.VipLevel {
	case 1:
		{
			Vip.Month = 1
			Vip.Price = 30.0
		}
	case 2:
		{
			Vip.Month = 3
			Vip.Price = 75.0
		}
	case 3:
		{
			Vip.Month = 12
			Vip.Price = 240.0
		}
	}
	if err := model.DB.Create(&Vip).Error; err != nil {
		return nil, err
	}
	var Ali = pkg.AliPay{
		Price:   Vip.Price,
		Title:   "会员续费",
		OrderNo: Vip.Snow,
	}
	return &vip.VipAddResponse{
		Url: Ali.VipPay(),
	}, nil
}
